package cn.gqr.controller.Public;

import cn.gqr.entity.Type;
import cn.gqr.service.BlogService;
import cn.gqr.service.TypeService;
import cn.gqr.uitl.RespJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("api/public")
public class BlogController {

    @Autowired
    BlogService bs;

    @Autowired
    TypeService ts;



    @RequestMapping("/findPage")
    @ResponseBody
    public Map findPage(Integer start,String title){
        System.out.println(start+"---"+title);
        return RespJson.pack(200,"博客信息",bs.findByPage(start,title,null));
    }

    @RequestMapping("/findPageType/{start}/{typeid}")
    @ResponseBody
    public Map findPageType(@PathVariable("start") Integer start,@PathVariable("typeid") String typeid){
        System.out.println(start+"---"+typeid);
        return RespJson.pack(200,"博客信息",bs.findByPage(start,null,typeid));
    }

    @RequestMapping("/getTypeAll")
    @ResponseBody
    public Map getTypeAll(){
        List<Type> types = ts.getTypeAll();
        return RespJson.pack(200,"分类信息",types);
    }

    @RequestMapping("/goFullText")
    public String goFullText(){
        return "client/article";
    }

    @RequestMapping("getBlogText/{blogId}")
    @ResponseBody
    public Map getBlogText(@PathVariable("blogId") String blogId){
        return RespJson.pack(200,"文章信息",bs.findByIdBlog(blogId));
    }

    @RequestMapping("addReadCount/{blogId}")
    public void addReadCount(@PathVariable("blogId") String blogId){
        bs.addReadCount(blogId);
    }


}
